Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

format: don't fail silently on invalid input anymore #1749

Merged
merged 1 commit into from
Jan 5, 2024

Conversation

yannham
Copy link
Member

@yannham yannham commented Jan 5, 2024

nickel format is silently doing nothing and exit with success code when the input file doesn't parse, which can be surprising (you think that you correctly formatted your codebase, but in fact the file doesn't even parse). This is due to using tolerate_parsing_errors: true, which as reported by @vkleen was a fix for a time when Topiary would simply erase some files upon parsing errors, which was of course problematic, to say the least.

This isn't the case anymore, and thus we can get rid of this option and correctly report parse errors when formatting.

@github-actions github-actions bot temporarily deployed to pull request January 5, 2024 12:03 Inactive
@vkleen
Copy link
Contributor

vkleen commented Jan 5, 2024

When trying to format a file containing a single { with this PR, while nickel doesn't erase the contents of the file anymore, it still silently pretends to succeed. Maybe we need to do something more when calling topiary?

@yannham
Copy link
Member Author

yannham commented Jan 5, 2024

In fact I noticed that unexpected end of file doesn't seem to cause any error, and the file is also actually formatted (although the last unclosed block is a bit messed up sometime). So something (Topiary, tree-sitter, or the Nickel grammar) is probably wired to handle incomplete input.

However, if you add an expression like 1 + + 2 somewhere in your file, this should fail. At least it does on my side.

Copy link
Contributor

@vkleen vkleen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right, with 1 + + 2 in the file it fails for me as well.

@yannham yannham added this pull request to the merge queue Jan 5, 2024
Merged via the queue into master with commit 77b9c57 Jan 5, 2024
5 checks passed
@yannham yannham deleted the fix/format-silent-failure branch January 5, 2024 14:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants